//
//  GenderPickerVIew.m
//  FlowerRainGround
//
//  Created by lanou on 16/4/22.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "GenderPickerVIew.h"


//性别的选择器
@interface GenderPickerVIew ()<UIPickerViewDataSource, UIPickerViewDelegate>
@property (nonatomic, strong) UIPickerView *pickerView;
@property (nonatomic, strong) NSArray *genderArray;
@property (nonatomic, strong) UILabel *titleLabel;

@end




@implementation GenderPickerVIew



- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 100, kWidth, 100)];
        self.pickerView.delegate = self;
        self.pickerView.dataSource = self;
        [self viewDidLoad];
        self.pickerView.showsSelectionIndicator = YES;
        [self addSubview:self.pickerView];
        
        //显示请选择性别的button
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake((kWidth - 100) / 2, 10, 100, 50)];
        self.titleLabel.text = @"请选择性别";
        self.titleLabel.textAlignment = 1;
        [self addSubview:self.titleLabel];
        
        //显示完成的button
        self.finishButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.finishButton.frame = CGRectMake(kWidth - 100, 10, 50, 50);
        [self.finishButton setTitle:@"完成" forState:UIControlStateNormal];
        [self addSubview:self.finishButton];
        
        
    }
    return self;
}


- (void)viewDidLoad {
    self.genderArray = [[NSArray alloc] initWithObjects:@"男", @"女", nil];
}

//列数
- (NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

//显示一列几个数据
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return self.genderArray.count;
}


//返回当前行的值
- (NSString *) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    self.gender =  [self.genderArray objectAtIndex:row];
    return self.gender;
}





/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
